package com.xuqi.Mail;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.xuqi.R;
import com.xuqi.menucontrol.MenuControlIF;
import com.xuqi.menucontrol.SCR_MenuBase;

public class MailMainInput extends SCR_MenuBase implements OnClickListener {

	private EditText m_etSender = null;
	private EditText m_etGetter = null;
	private EditText m_etContext = null;
	private Button m_btSend = null;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mailmaininput);
		
		m_etSender = (EditText) findViewById(R.id.sender);
		m_etGetter = (EditText) findViewById(R.id.gettter);
		m_etContext = (EditText) findViewById(R.id.mail_context);
		m_btSend = (Button) findViewById(R.id.mail_send);

		m_etGetter.setText(GetEmailAccountName());
		
		m_btSend.setOnClickListener(this);
	}

	@Override
	public void onClick(View v)
	{
		if (v == m_btSend)
		{
			SetEmailInfo();
		}
	}

	public String GetEmailAccountName()
	{
		String strAccountName = "";

		AccountManager accountManager = AccountManager.get(MenuControlIF.GetCurActivity());
		Account[] accounts = accountManager.getAccountsByType("com.google");

		if (null == accounts)
		{
			return strAccountName;
		}

		if (accounts.length > 0)
		{
			strAccountName = accounts[0].name;
		}

		if (null == strAccountName)
		{
			strAccountName = "";
		}

		return strAccountName;
	}

	private void SetEmailInfo()
	{
		Intent data = new Intent(Intent.ACTION_SEND_MULTIPLE);
		// Intent data = new Intent(Intent.ACTION_SEND);
		data.putExtra(Intent.EXTRA_EMAIL, new String[] { m_etContext.getText().toString() });
		data.putExtra(Intent.EXTRA_SUBJECT, "Test");
		data.putExtra(Intent.EXTRA_TEXT, m_etContext.getText());
		// data.putExtra(Intent.EXTRA_STREAM, null);
		data.setType("text/plain");
		startActivity(data);
	}
}
